(() => {
    // 继承
    class Animal {
        name: string
        constructor(name: string) {
            this.name = name
        }
        move(distance: number = 0) {
            console.log(`${this.name} moved ${distance}`);
        }
    }
    class Snake extends Animal {
        constructor(name: string) {
            // 这里的super是父类的构造函数
            super(name)
        }
        move(distance: number = 5) {
            console.log('子类蛇在爬行');
            // 这里的super是父类
            super.move(distance)
        }
    }
    const snake = new Snake('蛇')
    snake.move()


    // 修饰符
    class Person {
        // 公共的，子类和实例对象都可以访问
        public name: string
        // 私有的, 只有类本身可以访问,子类和实例对象都不行
        private skill: string
        constructor(name: string, skill: string) {
            this.name = name
            this.skill = skill
        }
        // 受保护的，类本身和子类都可以访问，实例对象不行
        protected work() {
            console.log('走路');
        }
    }

    const person = new Person('人', '摘果子')
    console.log(person.name);
    // console.log(person.skill);

    class Student extends Person {
        constructor(name: string, skill: string) {
            super(name, skill)
        }
        public eat() {
            // private修饰的成员，子类不能访问
            // this.skill = '吃西瓜'

            this.work()
        }
    }
    const student = new Student('学生', '上课')
    student.eat()


    // readonly & 参数属性
    class Animal2 {
        constructor(protected readonly name: string) {
            this.name = name
        }
        public move(distance: number = 0) {
            console.log(`走了${distance}米`);
        }
    }
    class Cat extends Animal2 {
        constructor(name: string) {
            super(name)
        }
        public changeName(name:string) {
            console.log(name);
            // name经过readonly修饰后，只读不写
            // this.name = name
        }
    }
    const cat = new Cat('小猫')
    cat.changeName('改名小狗')

})()